import http from '@/utils/http'

export const getCartAPI = ()=>{
    return http({
        url:'/member/cart'
    })
}

export const addCartAPI = ({skuId,count})=>{
    return http({
        url:'/member/cart',
        method:'POST',
        data:{
            skuId,
            count
        }
    })
}

export const delcartAPI = (skuIdArr:Array<string>) => {
    const ids = {
        ids:skuIdArr
    }
    return http({
        url:'/member/cart',
        method:'DELETE',
        data:ids
    })
}

interface MergeCartParams {
    skuId:String,
    selected:Boolean,
    count:Number
}
export const mergeCartAPI = (arr:Array<MergeCartParams>)=>{
    return http({
        url:'/member/cart/merge',
        method:'POST',
        data:arr
    })
}
//修改商品数量和选中状态
export const changeCountAPI = (id:String,selected:Boolean,count:Number)=>{
    return http({
        url:`/member/cart/${id}`,
        method:'PUT',
        data:{
            selected,
            count
        }
    })
}
//修改所有商品是否全选
export const changeAllSelected = (selected:String,ids:Array<string>)=>{
    return http({
        url:'/member/cart/selected',
        method:'PUT',
        data:{
            selected,
            ids
        }
    })
}

